//
//  BLSetController.m
//  Byelone
//
//  Created by 乔小乔 on 2021/1/31.
//

#import "BLSetController.h"
#import "BLSet_Cell_Index.h"
#import "BLSecurDetailController.h"
#import "BL_IssuView.h"

#import "BLForgetPsdVC.h"
static NSString *reuse_BLSet_Cell_Index= @"Reuse_BLSet_Cell_Index";
@interface BLSetController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableViewList;
@property (nonatomic, strong) NSArray *arrayData;
@property (nonatomic, strong) UIView *viewTop;
@property (nonatomic, strong) UILabel *labelTop;
@end

@implementation BLSetController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"安全设置";
    self.arrayData = @[@"更改密码",@"系统问题反馈",@"用户隐私协议",@"高信用、高活跃、高魅力的标签怎么能获取",@"珍珠、贝壳怎么使用及获取"];
    [self.tableViewList reloadData];
    self.labelTop.text = [NSString stringWithFormat:@"当前登录账号:%@",[BLUserManager shareUser].phone];
}

#pragma mark - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrayData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *title = self.arrayData[indexPath.row];
    CGRect frame = CGRectMake(0, 0, BL_WINDOW_WIDTH-30, 55);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(0,0)];
    
    BLSet_Cell_Index *cell = [tableView dequeueReusableCellWithIdentifier:reuse_BLSet_Cell_Index forIndexPath:indexPath];
    cell.labelTitle.text = title;
//    [cell reloadWithData:nil];
    
    cell.layoutTop.constant = 0;
    cell.layoutBottom.constant = 0;
    cell.viewLine.hidden = NO;
    if (indexPath.row == 0) {
        cell.layoutTop.constant = 7;
        maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(6,6)];
    }else if(indexPath.row == self.arrayData.count-1){
        cell.layoutBottom.constant = 20;
        maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(6,6)];
        cell.viewLine.hidden = YES;
    }
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = frame;
    //赋值
    maskLayer.path = maskPath.CGPath;
    cell.viewBj.layer.mask = maskLayer;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55+((indexPath.row==0)?7:0)+((indexPath.row==self.arrayData.count-1)?20:0);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    switch (indexPath.row) {
        case 0:
        {
            BLForgetPsdVC *vc = [[BLForgetPsdVC alloc]init];
//            vc.passWordType = BLPassWordTypeLogin;
//            vc.isReSet = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            [BL_IssuView showIssuView];
        }
            break;
        case 2:
        {
            BLSecurDetailController *vc = [[BLSecurDetailController alloc]initWithType:ViewType_Protocol];
            vc.title = [self.arrayData objectAtIndex:indexPath.row];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            BLSecurDetailController *vc = [[BLSecurDetailController alloc]initWithType:ViewType_Hight];
            vc.title = @"高信用、高魅力、高活跃";
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            BLSecurDetailController *vc = [[BLSecurDetailController alloc]initWithType:ViewType_Award];
            vc.title = @"珍珠细则";
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
            
        default:
            break;
    }
    
    NSString *title = self.arrayData[indexPath.row];
    if ([title isEqualToString:@"更改密码"]) {
      
    }else if([title isEqualToString:@"更改密码"]){
        
    }
   
}
#pragma mark - set&get
- (UITableView *)tableViewList{
    if (!_tableViewList) {
        _tableViewList = [[UITableView alloc]initWithFrame:CGRectMake(0, 37, BL_WINDOW_WIDTH, BL_CONTENT_HEIGHT-44)];
        [self.view addSubview:_tableViewList];
        _tableViewList.backgroundColor = [UIColor clearColor];
        _tableViewList.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableViewList.delegate = self;
        _tableViewList.dataSource = self;
        if (@available(iOS 11.0, *)) {
            _tableViewList.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else{
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        [_tableViewList registerNib:[UINib nibWithNibName:@"BLSet_Cell_Index" bundle:nil] forCellReuseIdentifier:reuse_BLSet_Cell_Index];
        _tableViewList.tableFooterView = [UIView new];
    }
    return _tableViewList;
}

- (UIView *)viewTop{
    if (!_viewTop) {
        _viewTop = [[UIView alloc]initWithFrame:CGRectMake(10, 0, BL_WINDOW_WIDTH-20, 30)];
        _viewTop.layer.cornerRadius = 5;
        _viewTop.layer.masksToBounds = YES;
        _viewTop.backgroundColor = [UIColor chColorWithHexString:@"#F0F1FF"];
        [self.view addSubview:_viewTop];
    }
    return _viewTop;
}
- (UILabel *)labelTop{
    if (!_labelTop) {
        _labelTop = [[UILabel alloc]initWithFrame:CGRectMake(8, 0, BL_WINDOW_WIDTH-36, 30)];
        _labelTop.font = [UIFont systemFontOfSize:14];
        _labelTop.textColor = [UIColor chColorWithHexString:@"#6C72F5"];
        [self.viewTop addSubview:_labelTop];
    }
    return _labelTop;
}
@end

